<?php
	require_once($GLOBALS['BIB'].'Pr_db/pr_historics.mex');
	$RegID = 0;
	if (!isset($_POST['tsv_DateEnd'])) {$_POST['tsv_DateEnd'] = 'null';} else { $_POST['tsv_DateEnd'] = "'{$_POST['tsv_DateEnd']}'"; }
	
	if ($_POST['smv_ID'] == 0) {
		$PID = 392;
		if($GLOBALS['MYT']->db_query("INSERT INTO systemoffice.staff_move (smv_DomainSrc, smv_DomainDst, smv_DateMov, smv_UserRequest, smv_UserID, smv_Motive, smv_Observations, smv_DateEnd)
		VALUES ({$_POST['MemberDomain']},{$_POST['smv_Domain']},'{$_POST['smv_DateMov']}',{$_SESSION[$SESSID]},{$_POST['MemberID']},'{$_POST['smv_Motive']}','{$_POST['smv_Observations']}',{$_POST['tsv_DateEnd']})")==true) {
			$GetRecord = $GLOBALS['MYT']->db_array("SELECT smv_ID FROM systemoffice.staff_move WHERE smv_UserRequest = {$_SESSION[$SESSID]} ORDER BY smv_ID DESC LIMIT 0,1");
			$GLOBALS['MYT']->db_query("INSERT INTO systemoffice.timeclock_staffoff (tsv_Flag, tsv_Member, tsv_Domain, tsv_DateStart, tsv_DateEnd, tsv_Process, tsv_Observations, tsv_User)
		VALUES (1,{$_POST['MemberID']},'{$_POST['smv_Domain']}','{$_POST['smv_DateMov']}',{$_POST['tsv_DateEnd']},{$PID},'',{$_SESSION[$SESSID]})");
		
			systemchange_hs('STAFF_NEWTRANSFER',$GetRecord[1]['smv_ID']);	
				$RegID = $GetRecord[1]['smv_ID'];
				$TaskTime = $_POST['smv_DateMov'];
		echo '<script charset="utf-8" type="text/javascript">document.staffmv.smv_ID.value='.$GetRecord[1]['smv_ID'].';</script>';			
		}
	} else {
		$PID = 0;
		if($GLOBALS['MYT']->db_query("UPDATE systemoffice.staff_move 
			SET 
				smv_DomainSrc = {$_POST['MemberDomain']}, 
				smv_DomainDst = {$_POST['smv_Domain']}, 
				smv_DateMov = '{$_POST['smv_DateMov']}', 
				smv_UserRequest = {$_SESSION[$SESSID]}, 
				smv_UserID = {$_POST['MemberID']}, 
				smv_Motive = '{$_POST['smv_Motive']}',
				smv_Observations = '{$_POST['smv_Observations']}',
				smv_DateEnd = {$_POST['tsv_DateEnd']}
			WHERE smv_ID = {$_POST['smv_ID']}")==true) {
			systemchange_hs('STAFF_EDITTRANSFER',$_POST['MemberID']);	
		}
	}
	if ($RegID != 0) {
	include($GLOBALS['BIB'].'Pr_db/prc_modules/rh_comunication.php');

		if ($_POST['tsv_DateEnd'] != 'null') {
		$PID = 393;
		$TaskTime = $_POST['tsv_DateEnd'];
		include($GLOBALS['BIB'].'Pr_db/prc_modules/rh_comunication.php');
		}
	}